<<<<<<< HEAD
import request from '@/utils/request'

// 获取商家信息
export function getMerchantInfo() {
  return request({
    url: '/api/merchant/info',
    method: 'get'
  })
}

// 更新商家信息
export function updateMerchantInfo(data) {
  return request({
    url: '/api/merchant/info',
    method: 'put',
    data
  })
}

// 修改密码
export function updateMerchantPassword(data) {
  return request({
    url: '/api/merchant/password',
    method: 'put',
    data
=======
import { get, post, put, del } from '@/utils/request'
import { API_ENDPOINTS, replaceUrlParams } from '@/config/api'

/**
 * 账户管理API
 */

// 获取商户资料
export function getMerchantProfile() {
  return get(API_ENDPOINTS.ACCOUNT.PROFILE)
}

// 获取商家信息（兼容旧版本）
export function getMerchantInfo() {
  return get('/api/merchant/info')
}

// 更新商户资料
export function updateMerchantProfile(profileData) {
  return put(API_ENDPOINTS.ACCOUNT.UPDATE_PROFILE, {
    name: profileData.name,
    phone: profileData.phone,
    email: profileData.email,
    address: profileData.address,
    region: profileData.region,
    description: profileData.description,
    serviceTypes: profileData.serviceTypes || []
  })
}

// 更新商家信息（兼容旧版本）
export function updateMerchantInfo(data) {
  return put('/api/merchant/info', data)
}

// 修改密码
export function changePassword(passwordData) {
  return post(API_ENDPOINTS.ACCOUNT.CHANGE_PASSWORD, {
    oldPassword: passwordData.oldPassword,
    newPassword: passwordData.newPassword,
    confirmPassword: passwordData.confirmPassword
  })
}

// 修改密码（兼容旧版本）
export function updateMerchantPassword(data) {
  return put('/api/merchant/password', data)
}

// 上传头像
export function uploadAvatar(file) {
  const formData = new FormData()
  formData.append('file', file)
  return post(API_ENDPOINTS.ACCOUNT.UPLOAD_AVATAR, formData, {
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

// 获取安全设置
export function getSecuritySettings() {
  return get(API_ENDPOINTS.ACCOUNT.SECURITY_SETTINGS)
}

// 更新安全设置
export function updateSecuritySettings(securityData) {
  return put(API_ENDPOINTS.ACCOUNT.SECURITY_SETTINGS, {
    twoFactorAuth: securityData.twoFactorAuth,
    loginNotification: securityData.loginNotification,
    allowedIps: securityData.allowedIps || [],
    sessionTimeout: securityData.sessionTimeout
  })
}

// 获取登录历史
export function getLoginHistory(params = {}) {
  return get(API_ENDPOINTS.ACCOUNT.LOGIN_HISTORY, {
    page: params.page || 0,
    size: params.size || 20,
    startDate: params.startDate || '',
    endDate: params.endDate || ''
>>>>>>> c61637f (所有前后端正常登录)
  })
}

// 获取货款账户信息
export function getLoanAccount() {
  return request({
    url: '/api/merchant/account/loan',
    method: 'get'
  })
}

// 获取保证金账户信息
export function getDepositAccount() {
  return request({
    url: '/api/merchant/account/deposit',
    method: 'get'
  })
}

// 提现操作
export function withdrawAllLoan() {
  return request({
    url: '/api/merchant/account/withdraw',
    method: 'post'
  })
}

// 充值操作
export function rechargeDeposit() {
<<<<<<< HEAD
  return request({
    url: '/api/merchant/account/recharge',
    method: 'post'
  })
=======
  return post('/api/merchant/account/recharge')
}

// 提交商户认证
export function submitMerchantCertification(certificationData) {
  return post('/api/merchant/certification', {
    shopName: certificationData.shopName,
    shopType: certificationData.shopType,
    contactName: certificationData.contactName,
    contactPhone: certificationData.contactPhone,
    region: certificationData.region,
    address: certificationData.address,
    licenseNo: certificationData.licenseNo,
    legalPerson: certificationData.legalPerson,
    establishDate: certificationData.establishDate,
    businessTerm: certificationData.businessTerm,
    serviceTypes: certificationData.serviceTypes,
    businessScope: certificationData.businessScope,
    licenseImage: certificationData.licenseImage,
    idCardImage: certificationData.idCardImage
  })
}

// 获取认证状态
export function getCertificationStatus() {
  return get('/api/merchant/certification/status')
}

// 获取认证详情
export function getCertificationDetail() {
  return get('/api/merchant/certification/detail')
}

// 申请退店
export function submitQuitStore(quitData) {
  return post('/api/merchant/quit-store', {
    reason: quitData.reason,
    description: quitData.description,
    contact: quitData.contact,
    checklist: quitData.checklist
  })
}

// 取消退店申请
export function cancelQuitStore() {
  return post('/api/merchant/quit-store/cancel')
}

// 获取退店申请状态
export function getQuitStoreStatus() {
  return get('/api/merchant/quit-store/status')
}

// 绑定手机号
export function bindPhone(phoneData) {
  return post('/api/account/bind-phone', {
    phone: phoneData.phone,
    verifyCode: phoneData.verifyCode,
    password: phoneData.password
  })
}

// 绑定邮箱
export function bindEmail(emailData) {
  return post('/api/account/bind-email', {
    email: emailData.email,
    verifyCode: emailData.verifyCode,
    password: emailData.password
  })
}

// 发送手机验证码
export function sendPhoneVerifyCode(phone) {
  return post('/api/account/send-phone-code', {
    phone: phone
  })
}

// 发送邮箱验证码
export function sendEmailVerifyCode(email) {
  return post('/api/account/send-email-code', {
    email: email
  })
}

// 商户状态枚举
export const MERCHANT_STATUS = {
  PENDING: 'pending',           // 待审核
  APPROVED: 'approved',         // 已审核
  REJECTED: 'rejected',         // 已驳回
  CERTIFIED: 'certified',       // 已认证
  SUSPENDED: 'suspended',       // 已暂停
  CLOSED: 'closed'              // 已关闭
}

// 商户状态文本映射
export const MERCHANT_STATUS_TEXT = {
  [MERCHANT_STATUS.PENDING]: '待审核',
  [MERCHANT_STATUS.APPROVED]: '已审核',
  [MERCHANT_STATUS.REJECTED]: '已驳回',
  [MERCHANT_STATUS.CERTIFIED]: '已认证',
  [MERCHANT_STATUS.SUSPENDED]: '已暂停',
  [MERCHANT_STATUS.CLOSED]: '已关闭'
}

// 服务类型枚举
export const SERVICE_TYPES = {
  LAUNDRY: 'laundry',           // 洗衣服
  SHOES: 'shoes',               // 洗鞋
  PETS: 'pets',                 // 洗萌宠
  BAGS: 'bags',                 // 洗包包
  BEDDING: 'bedding',           // 洗被子
  CAR_WASH: 'car_wash',         // 洗车
  HOME_CLEANING: 'home_cleaning', // 上门清洗
  PLUMBING: 'plumbing'          // 疏通厕所
}

// 服务类型文本映射
export const SERVICE_TYPE_TEXT = {
  [SERVICE_TYPES.LAUNDRY]: '洗衣服',
  [SERVICE_TYPES.SHOES]: '洗鞋',
  [SERVICE_TYPES.PETS]: '洗萌宠',
  [SERVICE_TYPES.BAGS]: '洗包包',
  [SERVICE_TYPES.BEDDING]: '洗被子',
  [SERVICE_TYPES.CAR_WASH]: '洗车',
  [SERVICE_TYPES.HOME_CLEANING]: '上门清洗',
  [SERVICE_TYPES.PLUMBING]: '疏通厕所'
}

// 手机号脱敏
export function maskPhone(phone) {
  if (!phone) return ''
  return phone.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2')
}

// 邮箱脱敏
export function maskEmail(email) {
  if (!email) return ''
  const [username, domain] = email.split('@')
  if (username.length <= 2) {
    return `${username}***@${domain}`
  }
  return `${username.substring(0, 2)}***@${domain}`
}

// 验证手机号格式
export function validatePhone(phone) {
  const phoneRegex = /^1[3-9]\d{9}$/
  return phoneRegex.test(phone)
}

// 验证邮箱格式
export function validateEmail(email) {
  const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
  return emailRegex.test(email)
>>>>>>> c61637f (所有前后端正常登录)
}